Skip to content

Python: Make encrypted reasoning opt-in for Foundry chat - #7536

Open
Evan Mattson (moonbox3) wants to merge 3 commits into
microsoft:mainfrom
moonbox3:codex/fix-7483-foundry-encrypted-reasoning-opt-in
Open

Python: Make encrypted reasoning opt-in for Foundry chat#7536
Evan Mattson (moonbox3) wants to merge 3 commits into
microsoft:mainfrom
moonbox3:codex/fix-7483-foundry-encrypted-reasoning-opt-in

Conversation

@moonbox3

@moonbox3 Evan Mattson (moonbox3) commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

FoundryChatClient inherits stateless OpenAI Responses behavior that automatically requests encrypted reasoning content. Foundry deployments such as GPT-4.1 reject that include value, causing otherwise ordinary chat requests to fail with a 400 response. Encrypted reasoning therefore needs to be controlled by the caller for Foundry deployments with different model capabilities.

Important

For reasoning models, encrypted reasoning content is opt-in. To request it, configure include in the agent's default options:

agent = Agent(
    ...,
    default_options={"include": ["reasoning.encrypted_content"]},
)

Description & Review Guide

  • What are the major changes? Override Foundry chat option preparation to remove only the framework-added reasoning.encrypted_content include value, while preserving an explicit caller opt-in. Add public-seam regression tests for both paths and record the provider rule in the function-loop specification.
  • What is the impact of these changes? Foundry chat calls work by default with deployments that do not support encrypted reasoning, while capable deployments can still request it explicitly. OpenAI chat-client behavior is unchanged.
  • What do you want reviewers to focus on? The distinction between caller-supplied and framework-injected include values, and consistency with the existing Foundry agent behavior.

Related Issue

Fixes #7483

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI lite review requested due to automatic review settings August 6, 2026 03:29
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the Python Foundry chat client so encrypted reasoning (reasoning.encrypted_content) is no longer implicitly requested, avoiding 400 failures on Foundry deployments/models that don’t support it, while still allowing callers to explicitly opt in.

Changes:

  • Override FoundryChatClient option preparation to strip framework-injected reasoning.encrypted_content unless the caller explicitly requested it.
  • Add regression tests covering default behavior (no encrypted reasoning) and explicit opt-in preservation.
  • Document the Foundry encrypted-reasoning opt-in rule in the Python function-calling loop specification.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
python/packages/foundry/agent_framework_foundry/_chat_client.py Removes implicit encrypted-reasoning include for Foundry chat requests unless explicitly requested by the caller.
python/packages/foundry/tests/foundry/test_foundry_chat_client.py Adds tests validating default omission and explicit opt-in forwarding of reasoning.encrypted_content.
docs/specs/004-python-function-calling-loop.md Records the Foundry-specific rule and links the relevant regression tests.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent Framework Skill Review

Completed passes: 5 | Failed passes: 0 | Confidence: 59% | Result: No high-severity findings

Review passes

  • Correctness (gpt-5.6-sol) — No high-confidence issues found in this pass.
  • Security Reliability (claude-opus-4.8) — No high-confidence issues found in this pass.
  • Test Coverage (gpt-5.6-sol) — The new tests do not cover preservation of unrelated include values after filtering, so a regression that removes all caller-suplied includes could pass unnoticed.
  • Failure Modes (claude-opus-4.8) — No high-confidence issues found in this pass.
  • Design Approach (claude-opus-4.8) — No high-confidence issues found in this pass.

No high-severity findings survived the review and verification pipeline.


PR ensemble review by moonbox3's agents

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/foundry/agent_framework_foundry
   _chat_client.py2532291%112, 114–116, 120–121, 125, 221, 268, 277, 333, 338, 389, 601, 605, 699, 706–709, 756, 838
TOTAL45715424890% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9296 36 💤 0 ❌ 0 🔥 2m 31s ⏱️

@moonbox3

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent Framework Review — Iteration 2

Completed passes: 5 | Failed passes: 0 | Result: No high-severity findings

Scope: 1 net-new commit(s): 71e71dce562d

Review passes

  • Correctness (gpt-5.6-sol) — No high-confidence issues found in this pass.
  • Security Reliability (claude-opus-4.8) — No high-confidence issues found in this pass.
  • Test Coverage (gpt-5.6-sol) — No high-confidence issues found in this pass.
  • Failure Modes (claude-opus-4.8) — No high-confidence issues found in this pass.
  • Design Approach (claude-opus-4.8) — No high-confidence issues found in this pass.

@moonbox3
Evan Mattson (moonbox3) requested a balanced review from Copilot August 6, 2026 23:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (3)

python/packages/foundry/agent_framework_foundry/_chat_client.py:271

  • The removal logic only runs when run_options['include'] is a list. If upstream returns (or a middleware sets) include as a tuple/sequence, the framework-injected reasoning.encrypted_content won’t be stripped and Foundry deployments may still 400. Consider handling broader iterables (e.g., Sequence[str]) by normalizing include to a list before filtering, and only emitting include when non-empty.
    @override
    async def _prepare_options(
        self,
        messages: Sequence[Message],
        options: Mapping[str, Any],
    ) -> dict[str, Any]:
        """Prepare Foundry options without implicitly requesting encrypted reasoning."""
        caller_requested_encrypted_reasoning = "reasoning.encrypted_content" in (options.get("include") or [])
        run_options = await super()._prepare_options(messages, options)
        if not caller_requested_encrypted_reasoning and isinstance(run_options.get("include"), list):
            include = [item for item in run_options["include"] if item != "reasoning.encrypted_content"]
            if include:
                run_options["include"] = include
            else:
                run_options.pop("include")
        return run_options

python/packages/foundry/tests/foundry/test_foundry_chat_client.py:461

  • These tests validate presence/absence of the encrypted include value, but they don’t assert the stronger behavior implemented in _prepare_options: when the only included item is the framework-added encrypted reasoning, the include field is removed entirely (not sent as include=[]). Consider asserting on the actual kwargs passed to with_raw_response.create (e.g., by inspecting call_args.kwargs) to ensure the include key is omitted when appropriate.
    async def create_response(**kwargs: Any) -> Any:
        if "reasoning.encrypted_content" in kwargs.get("include", []):
            raise ValueError("Encrypted content is not supported with this model.")
        return _as_raw(mock_response)

python/packages/foundry_hosting/tests/test_responses_int.py:629

  • Adding include: ['reasoning.encrypted_content'] at this shared default_options construction site can change the behavior of any tests that reuse this boundary/server setup. If only specific replay scenarios require encrypted reasoning, it would be less coupling to scope the opt-in to the smallest possible test surface (e.g., set it only for the specific test/agent instance that needs it), or add a short comment here explaining why all consumers of this helper must opt in.
            default_options={  # pyrefly: ignore[bad-argument-type]
                "store": False,
                "reasoning": {"effort": "low", "summary": "auto"},
                "include": ["reasoning.encrypted_content"],
            },
        )
        server = ResponsesHostServer(agent, store=InMemoryResponseProvider())

@moonbox3
Evan Mattson (moonbox3) added this pull request to the merge queue Aug 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Encrypted content is not supported with this model for GPT-4.1 model

4 participants